//
//  UITextField+Placeholder.m
//  BuDeJie
//
//  Created by demoncraz on 2017/2/12.
//  Copyright © 2017年 demoncraz. All rights reserved.
//

#import "UITextField+Placeholder.h"
#import <objc/message.h>

@implementation UITextField (Placeholder)

+ (void)load {
    //交换方法
    Method setPlaceholder = class_getInstanceMethod(self, @selector(setPlaceholder:));
    Method CC_setPlaceholder = class_getInstanceMethod(self, @selector(CC_setPlaceholder:));
    
    method_exchangeImplementations(setPlaceholder, CC_setPlaceholder);
}

- (UIColor *)placeholderColor {
    return objc_getAssociatedObject(self, @"placeholderColor");
}

- (void)setPlaceholderColor:(UIColor *)placeholderColor {
    
    objc_setAssociatedObject(self, @"placeholderColor", placeholderColor, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
    
    UILabel *placeholderLabel = [self valueForKeyPath:@"placeholderLabel"];
    
    placeholderLabel.textColor = placeholderColor;
}

- (void)CC_setPlaceholder:(NSString *)placeholder {
    [self CC_setPlaceholder:placeholder];
    self.placeholderColor = self.placeholderColor;
}



@end
